<?php 
session_start();
require('../../connections/con_gl.php'); 
mysql_select_db($database_con_gl, $con_gl);
$area = $_REQUEST['area'];
list($namaarea) = mysql_fetch_row(mysql_query("select area from gl_area where id='$area'"));
?>
<!--<p><a style="cursor:pointer;" onclick="window.print();"><img src="images/_print.PNG" />&nbsp;&nbsp;Cetak</a></p>-->
<h3 align="center">STOK KENDARAAN CABANG</h3>
<table width="100%" border="1" cellspacing="0" cellpadding="3">
	<tr style="text-align:center;background-color:#eee">
		<th width="3%" rowspan="3">No.</th>
		<th width="40%" colspan="3" rowspan="3">Jenis Kendaraan</th>
		<?php 
		$str = "select id, area from gl_area ";
		if($area != '') $str .= " where id='$area' ";
		$str .= "order by area asc ";
		$query = mysql_query($str) or die (mysql_error());
		while(list($idarea, $namaarea) = mysql_fetch_row($query)){
		list($jmlcabang) = mysql_fetch_row(mysql_query("select count(*) from gl_gudang where area='$idarea'"));
		echo "<th colspan='".($jmlcabang*4)."'>$namaarea</th>";
		}
		?>
	</tr>
	<tr style="text-align:center;background-color:#eee">
		<?php 
		$str = "select id, area from gl_area ";
		if($area != '') $str .= " where id='$area' ";
		$str .= "order by area asc ";
		$query = mysql_query($str) or die (mysql_error());
		while(list($idarea, $namaarea) = mysql_fetch_row($query)){
			$qcb = mysql_query("select id, gudang from gl_gudang where area = '$idarea' order by gudang asc") or die (mysql_error());
			$jqcb = mysql_num_rows($qcb);
			if($jqcb=='0'){
			echo "<th align='center'>&nbsp;</th>";
			}else{
			while(list($idgudang, $namagudang) = mysql_fetch_row($qcb)){
			echo "<th align='center' colspan='4'>$namagudang</th>";
			}
			}
		}
		?>
	</tr>
	<tr style="text-align:center;background-color:#eee">
		<?php 
		$str = "select id, area from gl_area ";
		if($area != '') $str .= " where id='$area' ";
		$str .= "order by area asc ";
		$query = mysql_query($str) or die (mysql_error());
		while(list($idarea, $namaarea) = mysql_fetch_row($query)){
			$qcb = mysql_query("select id, gudang from gl_gudang where area = '$idarea' order by gudang asc") or die (mysql_error());
			$jqcb = mysql_num_rows($qcb);
			if($jqcb=='0'){
			echo "<th align='center'>&nbsp;</th>";
			}else{
			while(list($idgudang, $namagudang) = mysql_fetch_row($qcb)){
			echo "<th align='center'>CORP</th>";
			echo "<th align='center'>RTL</th>";
			echo "<th align='center'>Tugas Kantor</th>";
			echo "<th align='center'>UGC</th>";
			}
			}
		}
		?>
	</tr>
	<?php
	$str = "select distinct a.merk, b.merk, a.tipekendaraan, c.tipekendaraan, a.jeniskendaraan, d.jeniskendaraan from gl_masterkendaraan as a left join gl_merkkendaraan as b on (a.merk=b.id) left join gl_tipekendaraan as c on (a.tipekendaraan=c.id) inner join gl_jeniskendaraan as d on (a.jeniskendaraan=d.id) "; //echo $str;
	if($area!='') $str.=" where a.area='$area'"; 
	$str .= " order by a.merk asc "; //echo $str;
	$query = mysql_query($str) or die (mysql_error());
	//print_r($str);
	$no=1;
	while(list($idmerk, $merk, $idtipe, $tipe, $idjenis, $jenis) = mysql_fetch_row($query)){
	echo "<tr>";
	echo "<td align='center'>$no.</td>";
	echo "<td align='center'>$merk</td>";
	echo "<td align='center'>$jenis</td>";
	echo "<td width='160' align='center'>$tipe</td>";
	$strsub = "select id, area from gl_area ";
	if($area != '') $strsub .= " where id='$area' ";
	$strsub .= "order by area asc ";
	$querysub = mysql_query($strsub) or die (mysql_error());
	while(list($idarea, $namaarea) = mysql_fetch_row($querysub)){
		$qcb = mysql_query("select id, gudang from gl_gudang where area = '$idarea' order by gudang asc") or die (mysql_error());
		$jqcb = mysql_num_rows($qcb);
		if($jqcb=='0'){
		echo "<th align='center'>&nbsp;</th>";
		}else{
		while(list($idgudang, $namagudang) = mysql_fetch_row($qcb)){
		$strsub2 = "select count(*) from gl_masterkendaraan where merk='$idmerk' and tipekendaraan='$idtipe' and jeniskendaraan='$idjenis' and unitstok='1' and cabang='$idgudang' ";
		if($area!='') $strsub2.=" and area='$area' ";
		list($jmlretail) = mysql_fetch_row(mysql_query($strsub2)); if($jmlretail==0) $jmlretail="";
		echo "<td align='center'>$jmlretail</td>";
		$strsub2 = "select count(*) from gl_masterkendaraan where merk='$idmerk' and tipekendaraan='$idtipe' and jeniskendaraan='$idjenis' and unitstok='2' and cabang='$idgudang'";
		if($area!='') $strsub2.=" and area='$area' ";
		list($jmlcorporate) = mysql_fetch_row(mysql_query($strsub2)); if($jmlcorporate==0) $jmlcorporate="";
		echo "<td align='center'>$jmlcorporate</td>";
		$strsub2 = "select count(*) from gl_masterkendaraan where merk='$idmerk' and tipekendaraan='$idtipe' and jeniskendaraan='$idjenis' and unitstok='3' and cabang='$idgudang' ";
		if($area!='') $strsub2.=" and area='$area' ";
		list($jmloperational) = mysql_fetch_row(mysql_query($strsub2)); if($jmloperational==0) $jmloperational="";
		echo "<td align='center'>$jmloperational</td>";
		$strsub2 = "select count(*) from gl_masterkendaraan where merk='$idmerk' and tipekendaraan='$idtipe' and jeniskendaraan='$idjenis' and unitstok='4' and cabang='$idgudang' ";
		if($area!='') $strsub2.=" and area='$area' ";
		list($jmlcargo) = mysql_fetch_row(mysql_query($strsub2)); if($jmlcargo==0) $jmlcargo="";
		echo "<td align='center'>$jmlcargo</td>";
		}
		}
	}
	echo "</tr>";
	$no++;
	}
	?>
</table>

<div id="box-exportdata">

<a href="doc/laporanUnitCabangPDF2.php?area=<?php echo $area; ?>" title="Export PDF"><img src="images/_print.png" border="0" /></a><br /><br />

<!--
<a href="doc/laporanUnitCabangPDF.php?area=<?php echo $area; ?>" title="Export PDF"><img src="images/_print.png" border="0" /></a><br /><br />
-->
<a href="doc/laporanUnitCabangExcel.php?area=<?php echo $area; ?>&amp;files='Stok Kendaraan Cabang'" title="Export Excel"><img src="images/_xls.png" border="0" /></a><br /><br />
<a href="doc/laporanUnitCabangDoc.php?area=<?php echo $area; ?>&amp;files='Stok Kendaraan Cabang'" title="Export Word"><img src="images/_word.png" border="0" /></a>
</div>

<p>&nbsp;</p>